<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>跑马灯效果</title>
    <script src="../vue.min.js"></script>
    <style>
        ul {
            display: none;
            list-style: none;
        }
    </style>
</head>

<body>
    <div id="app">
        <input type="button" value="run" @click="run()">
        <input type="button" value="stop" @click="stop()">
        <p>{{msg}}</p>
    </div>
    <script>
        var Vm = new Vue({
            el: "#app",
            data: {
                msg: "历一方水土，知一番人是；天地不仁，万物刍狗;",
                setInt: null,
            },
            methods: {
                run: function () {
                    var that = this;
                    if (this.setInt != null) {
                        return;
                    }
                    this.setInt = setInterval(function () {
                        var start = that.msg.substring(0, 1);
                        var end = that.msg.substring(1);
                        that.msg = end + start;
                    }, 400)
                },
                stop() {
                    clearInterval(this.setInt);
                    this.setInt = null;
                }
            }
        })
    </script>
</body>

</html>